import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import "qrc:///MyControls"

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Mine")

    //背景颜色
    color: CTheme.background
    Item{
        id:titleBar
        height: 50
        width: parent.width
        anchors.top: parent.top

        Item{
            id:rowL
            anchors.fill: parent
            anchors.margins: 5
            CButton{
                id:restart
                text: "重新开始"
                width:80
                height: parent.height
                onClicked: {
                    mineView.startGame();
                }
            }

            CButton{
                id:btnMenu
                text: "难度"
                width:80
                height: parent.height
                anchors.right: parent.right
                onClicked: {
                    dialogGameLevel.open()
                }
            }

            Text {
                  color: "#ffffff"
                  text: mineView.flagCnt + "/" + mineView.mineCnt
                  anchors.centerIn: parent
            }
        }
    }
    Item{
        width: parent.width
        anchors.top: titleBar.bottom
        anchors.bottom: parent.bottom

        MineView{
            id:mineView
            anchors.fill: parent
        }

//        BrotherMineView{
//            id:mineView

//            anchors.fill: parent
//        }
    }


//    HomeView{
//        anchors.fill: parent

//    }
    DialogGameLevel{
        id: dialogGameLevel
        onLevelChanged:{
            mineView.setLevel(level);
        }
    }

    DialogGameOver{
        id:dialogGameOver

        onNewGame: {
            mineView.startGame();
        }

        Connections{
            target:  mineView
            onGameOver:{
                if(success){
                    dialogGameOver.title = "游戏成功!";
                    dialogGameOver.open();
                }else{
                    dialogGameOver.title = "游戏失败!";
                    dialogGameOver.open();
                }
            }
        }
    }

}
